//
//  CommonSectionComponent.swift
//  ClockWidget
//
//  Created by TSYH on 2023/10/17.
//

import UIKit

open class CommonSectionComponent: TSCollectionViewSectionComponent {
    open var cellComponents: [TSCollectionViewCellComponent]
    open var header: TSCollectionViewReuseViewComponent?
    open var footer: TSCollectionViewReuseViewComponent?
    open var inset: UIEdgeInsets
    open var rowSpacing: CGFloat
    open var columnSpacing: CGFloat
    
    public init(cellComponents: [TSCollectionViewCellComponent],
         header: TSCollectionViewReuseViewComponent? = nil,
         footer: TSCollectionViewReuseViewComponent? = nil,
         inset: UIEdgeInsets = .zero,
         rowSpacing: CGFloat = 10.0,
         columnSpacing: CGFloat = 10.0) {
        self.cellComponents = cellComponents
        self.header = header
        self.footer = footer
        self.inset = inset
        self.rowSpacing = rowSpacing
        self.columnSpacing = columnSpacing
    }
    
    open var cells: [TSCollectionViewCellComponent] {
        return cellComponents
    }
    
    open var headerComponent: TSCollectionViewReuseViewComponent? {
        return header
    }
    
    open var footerComponent: TSCollectionViewReuseViewComponent? {
        return footer
    }
    
    open func clear() {
        cellComponents.removeAll()
    }
    
    open func append(_ cellComponents: [TSCollectionViewCellComponent]) {
        self.cellComponents.append(contentsOf: cellComponents)
    }
   
    open var sectionInset: UIEdgeInsets {
        return inset
    }
    
    open var lineSpacing: CGFloat {
        return rowSpacing
    }
    
    open var itemSpacing: CGFloat {
        return columnSpacing
    }
}
